package com.asiainfo.kbisheet.components.condition
{
	import mx.controls.Alert;
	import mx.controls.Spacer;
	import mx.core.IVisualElement;
	
	import spark.components.Button;
	import spark.components.HGroup;
	import spark.components.VGroup;
	
	/**
	 * 一组查询条件，从布局上会显示在一排上。 
	 */
	public class ConditionGroup extends VGroup
	{
		private var conditionGroupXML:XML;
		/*当前水平容器*/
		private var chGroup:HGroup;
		
		public function ConditionGroup(xml:XML)
		{
			super();
			conditionGroupXML = xml;		
		}
		
		override protected function createChildren():void {
			super.createChildren();
			
			for each(var conditionXML:XML in conditionGroupXML.condition){
				addConditionElement(ConditionItemFactory.create(conditionXML));
			}
		}
		
		private function addConditionElement(element:IVisualElement):void{
			if(chGroup == null || (element is ConditionItem && ConditionItem(element).newline)){
				chGroup = new HGroup();
				chGroup.percentWidth = 100;
				addElement(chGroup);
			}
			
			chGroup.addElement(element);
		}
		
		public function addQueryButton(queryButton:Button):void{
			if(chGroup == null || (numElements < 2)){
				chGroup = new HGroup();
				chGroup.percentWidth = 100;
				addElement(chGroup);
			}
			var spacer:Spacer = new Spacer();
			spacer.percentWidth = 100;

			chGroup.addElement(spacer);
			chGroup.addElement(queryButton);
		}
	}
}